﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace LuShanTea.Web.Common
{
    public class LuShanEmailSms
    {
        public string Email { get; set; }

        public string Code { get; set; }
        /// <summary>
        /// 授权码：tttsewudfwqudeaf
        /// </summary>
        /// <returns></returns>

        public AjaxResult Send()
        {
            using (MailMessage mailMessage = new MailMessage())
            using (SmtpClient smtpClient = new SmtpClient("smtp.exmail.qq.com"))
            {
                mailMessage.To.Add(Email);
                mailMessage.Body = $"您好，欢迎注册庐山云雾茶，您的验证码是：{Code},请您尽快填写，5分钟之内有效";
                mailMessage.From = new MailAddress("zsz@amortal.cn");
                mailMessage.Subject = "庐山云雾茶";
                smtpClient.EnableSsl = true;
                smtpClient.Port = 587;
                smtpClient.Credentials = new System.Net.NetworkCredential("腾讯企业邮箱地址", "秘钥");
                try
                {
                    smtpClient.Send(mailMessage);
                    return new AjaxResult { Status = "ok" };
                }
                catch (Exception ex)
                {
                    return new AjaxResult { Status = "error",ErrorMsg=ex.Message };
                }
            }
        }
    }
}
